package dfs_bfs.leetcode_39;

import java.util.ArrayList;
import java.util.List;

public class Debug {
    public List<List<Integer>> combinationSum(int[] candidates, int target) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        dfs(candidates, 0, target, path, res);
        return res;
    }
    public void dfs(int[] arr, int index, int target, List<Integer> path, List<List<Integer>> res) {
        if (target < 0) {
            return;
        }
        if (target == 0) {
            res.add(new ArrayList<>(path));
            return;
        }
        for (int i = index; i < arr.length; i++) {
            path.add(arr[i]);
            dfs(arr, i, target - arr[i], path, res);
            path.remove(path.size() - 1);
        }
    }

    public static void main(String[] args) {
        int[] nums = new int[] {2,3,6,7};
        new Debug().combinationSum(nums, 7);
    }
}
